package com.yj.ccs.abs.boot.authorization.session;

import com.yj.ccs.abs.web.management.entity.User;
import lombok.Data;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/14
 * Author     : Unbelievable9
 **/
@Component
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Data
public class UserSession {

    private User user;

    public void login(User user) {
        this.user = user;
    }

    public void logout() {
        this.user = null;
    }

    public Boolean isLoggedIn() {
        return this.user != null && this.user.getId() != null;
    }
}
